/*
 * @Author: zhangyun
 * @Date: 2021-04-26 09:10:21
 * @LastEditors: zhangyun
 * @LastEditTime: 2021-04-27 14:33:05
 * @Desc:
 */
const express = require('express')
const app = express()
const port = 3030
const bodyParser = require('body-parser')
const cookieParser = require('cookie-parser')
const message = require('./utils/message.js')
const auth = require('./middleware/auth.js')
// router
const userRouter = require('./routes/user.js')
const loginRouter = require('./routes/login.js')
const ideaRouter = require('./routes/idea.js')
const articleRouter = require('./routes/article.js')

// app.use(cookieParser)
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

//设置允许跨域访问该服务.
app.all('*', function (req, res, next) {
  res.header('Access-Control-Allow-Origin', '*')
  res.header('Access-Control-Allow-Headers', 'Content-Type')
  res.header('Access-Control-Allow-Methods', '*')
  res.header('Content-Type', 'application/json;charset=utf-8')
  next()
})
app.get('/', (req, res) => {
  res.send('hello world!')
})
app.use('/user', userRouter)
app.use('/login', loginRouter)
app.use('/idea', ideaRouter)
app.use('/article', articleRouter)

app.listen(port, () => {
  console.info(`Example app listening at http://localhost:${port}`)
})
